package com.sen.design.pattern.creational.simplefactory;

import java.util.Optional;

/**
 * 简单工厂：由一个工厂对象决定创建出哪一种产品类的实例
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Video video = new JavaVideo();
        video.produce();

        // 通过简单工厂模式
        VideoFactory videoFactory = new VideoFactory();
        Video java = videoFactory.getVideo("java");
        java.produce();

        // 通过反射来创建工厂模式
        Video video1 = VideoFactory.getVideo(PythonVideo.class);
        Video video2 = Optional.ofNullable(video1).orElseThrow(() -> new Exception("获取对象错误"));
        video2.produce();

    }

}
